package com.esp.feign.feignservice.config;

import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import feign.Retryer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Project:spring-boot-new-publish-system-12
 * ClassName:FeignConfig
 * Package:com.esp.feign.feignservice.config
 * User:CWQ
 * Description:
 *
 * @Author 合肥-陈万琼
 * @Create 2024/5/31 23:47
 * @Version 1.0
 */
@Slf4j
@Configuration
public class FeignConfig {
    @Bean
    public RequestInterceptor requestInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                log.info("feign 请求前添加请求头");
                requestTemplate.header("Authorization", "Bearer your-token");
            }
        };
    }

    @Bean
    public Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }

    @Bean
    public Retryer retryer(){
        // 初始重试间隔时间 （默认按照1.5倍递增）
        // 最大重试间隔时间
        // 最大重试次数
        return new Retryer.Default(100,1000,5);
    }

}
